<?php

// phpMyRealty 3
//
// File Name: stats.php
// File Location : ./admin/
//
// Copyright (c)2009 phpMyRealty.com
//
// e-mail: support@phpMyRealty.com

if (!defined('PMRADMIN') || (defined('PMRADMIN') && PMRADMIN != 'true')) die();

if ($encoder == 'I') $ioncube = 'ionCube/'; else $ioncube = 'Zend/';

echo '<table width="100%" cellpadding="0" border="0"><tr><td width="50%" align="center" valign="top">';

$PG = new PowerGraphic;

$PG->title = $lang['Admin_Stats_Listings_Title'];
$PG->type  = "2";

  array_push($PG->x, $lang['Admin_Stats_Active']);
  array_push($PG->x, $lang['Admin_Stats_Inactive']);

$sql = 'SELECT * FROM ' . PROPERTIES_TABLE . ' WHERE approved = 1';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
$f = $db->fetcharray($r);
  array_push($PG->y,$db->numrows($r));

$sql = 'SELECT * FROM ' . PROPERTIES_TABLE . ' WHERE approved = 0';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
$f = $db->fetcharray($r);
  array_push($PG->y,$db->numrows($r));

echo '<img src="' . URL . '/includes/functions/' . $ioncube . 'graph.php?' . $PG->create_query_string() . '" alt="" />';

$PG->reset_values();

echo '</td><td width="50%" align="center" valign="top">';

$PG = new PowerGraphic;

$PG->title = $lang['Admin_Stats_Users_Title'];
$PG->type  = "2";

  array_push($PG->x, $lang['Admin_Stats_Active']);
  array_push($PG->x, $lang['Admin_Stats_Inactive']);

$sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE approved = 1';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
$f = $db->fetcharray($r);
  array_push($PG->y,$db->numrows($r));

$sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE approved = 0';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
$f = $db->fetcharray($r);
  array_push($PG->y,$db->numrows($r));

echo '<img src="' . URL . '/includes/functions/' . $ioncube . 'graph.php?' . $PG->create_query_string() . '" alt="" />';

$PG->reset_values();

echo '</td></tr><table>';

// 

echo '<table width="100%" cellpadding="0" border="0"><tr><td width="50%" align="center" valign="top">';

$PG = new PowerGraphic;

$PG->title = $lang['Listing_Property_Type'];
$PG->type  = "2";

$sql = 'SELECT ' . $language_in . ', name, counter FROM ' . TYPES_TABLE . ' ORDER BY name';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
while ($f = $db->fetcharray($r))
 {
 
 if ($f[0] != '')
 	$f['name'] = $f[0];
 
  array_push($PG->x,$f['name']);
  array_push($PG->y,$f['counter']);
 }

echo '<img src="' . URL . '/includes/functions/' . $ioncube . 'graph.php?' . $PG->create_query_string() . '" alt="" />';

$PG->reset_values();

echo '</td><td width="50%" align="center" valign="top">';

$PG = new PowerGraphic;

$PG->title = $lang['Module_Listing_Type'];
$PG->type  = "2";

$sql = 'SELECT ' . $language_in . ', name, id FROM ' . TYPES2_TABLE . ' ORDER BY name';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
while ($f = $db->fetcharray($r))
 {
 
 if ($f[0] != '')
 	$f['name'] = $f[0];
 
  array_push($PG->x,$f['name']);
  
  $sql = 'SELECT id FROM ' . PROPERTIES_TABLE . ' WHERE type2 = ' . $f['id'] . '';
  $r2 = $db->query ( $sql ) or error ('Critical Error', mysql_error () );
  array_push($PG->y,$db->numrows($r2));
 }

echo '<img src="' . URL . '/includes/functions/' . $ioncube . 'graph.php?' . $PG->create_query_string() . '" alt="" />';

$PG->reset_values();

echo '</td></tr><table>';

//

echo '<table width="100%" cellpadding="0" border="0"><tr><td width="50%" align="center" valign="top">';

$PG = new PowerGraphic;

$PG->title = $lang['Admin_Stats_Images'];
$PG->type  = "2";

  array_push($PG->x,'User Photos / Logos');
  array_push($PG->y, countfiles ('photos')-0.5);

  array_push($PG->x,'Property Main Images');
  array_push($PG->y, countfiles ('images')-0.5);

  array_push($PG->x,'Photo Gallery Images');
  array_push($PG->y, countfiles ('gallery')-0.5);

  array_push($PG->x,'Property Banner Ads');
  array_push($PG->y, countfiles ('banners'));

echo '<img src="' . URL . '/includes/functions/' . $ioncube . 'graph.php?' . $PG->create_query_string() . '" alt="" />';

$PG->reset_values();

echo '</td><td width="50%" align="center" valign="top">';

$PG = new PowerGraphic;

$PG->title = $lang['Admin_Stats_Featured_Title'];
$PG->type  = "2";

$sql = 'SELECT * FROM ' . PROPERTIES_TABLE . ' WHERE featured = "A"';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );

  array_push($PG->x,'Featured Listings');
  array_push($PG->y,$db->numrows($r));

$sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE package > 0';
$r = $db->query ( $sql ) or error ('Critical Error', mysql_error () );

  array_push($PG->x,'Featured Accounts');
  array_push($PG->y,$db->numrows($r));

echo '<img src="' . URL . '/includes/functions/' . $ioncube . 'graph.php?' . $PG->create_query_string() . '" alt="" />';

$PG->reset_values();

echo '</td></tr></table>';

?>